import type { EamCheckMaintainPlan, EamCheckMaintainPlanEquipment, EamCheckMaintainPlanProgram } from "@/pages/eam/checkMaintainPlan/entity";
import apiClient from "../../apiClient";
import type { Result } from "#/api";

export interface PageListReq {
  //计划名称
  planName?: string;
  //计划类型
  planType?: string;
  //开始日期
  startDate?: Date;
  //结束日期
  endDate?: Date;
  //频率
  cycleType?: number;
  //周期类型
  periodType?: string;
  //状态
  status?: string;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: EamCheckMaintainPlan[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/eam/check/maintain/plan/pageList",
    data
});
const getInfo = (id: React.Key): Promise<EamCheckMaintainPlan> =>
  apiClient.get({
    url: `/eam/check/maintain/plan/${id}`
});

const add = (data: EamCheckMaintainPlan): Promise<EamCheckMaintainPlan> =>
  apiClient.post({
    url: "/eam/check/maintain/plan",
    data
});

const update = (data: EamCheckMaintainPlan): Promise<EamCheckMaintainPlan> =>
  apiClient.put({
    url: "/eam/check/maintain/plan",
    data
});

const remove = (ids: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/eam/check/maintain/plan",
    params: {
    ids: ids.join(",")
  }
});
const getequipments = (id: React.Key): Promise<EamCheckMaintainPlanEquipment[]> =>
  apiClient.post({
    url: "/eam/check/maintain/plan/equipment/list",
    data: {
      planId: id
    }
  });

const getprograms = (id: React.Key): Promise<EamCheckMaintainPlanProgram[]> =>
  apiClient.post({
    url: "/eam/check/maintain/plan/program/list",
    data: {
      planId: id
    }
  });

const changeStatus = (data: EamCheckMaintainPlan): Promise<Result> => 
  apiClient.post({
    url: "/eam/check/maintain/plan/status/change",
    data
  });
 
// 生成点检保养任务
const createReport = (data: EamCheckMaintainPlan): Promise<Result> =>
  apiClient.post({
    url: "/eam/check/maintain/plan/excute",
    data
  });

export const eamCheckMaintainPlanService = {
  pageList,
  getInfo,
  add,
  update,
  remove,
  getequipments,
  getprograms,
  changeStatus,
  createReport
};

export default eamCheckMaintainPlanService;